package command

import (
	"strings"

	"ssdevice/common/dto"
	"ssdevice/common/utils"
	"ssdevice/internal/device/models"
)

type ProdVariableInsertReq struct {
	ProductModel string                  `json:"productModel" vd:"len($)>0"`
	Key          string                  `json:"key" vd:"len($)>0"`
	Label        string                  `json:"label"`
	Type         string                  `json:"type"`
	Config       *map[string]interface{} `json:"config"`
	Param        *map[string]interface{} `json:"param"`
	Index        *int                    `json:"index"`
	dto.UserInfo `search:"-"`
}

func (d *ProdVariableInsertReq) Generate(model *models.SysProductVariable) {
	model.ProductModel = strings.TrimSpace(d.ProductModel)
	model.Key = strings.TrimSpace(d.Key)
	model.Label = strings.TrimSpace(d.Label)
	if len(model.Label) == 0 {
		model.Label = model.Key
	}
	model.Type = d.Type
	if d.Config != nil {
		model.Config = utils.MapToBytes(*d.Config)
	}
	if d.Param != nil {
		model.Param = utils.MapToBytes(*d.Param)
	}
	model.Index = d.Index
}

type ProdVariableDeleteReq struct {
	ModelKey map[string][]string `json:"modelKey"`

	dto.UserInfo `search:"-"`
}
